<%@ include file="/jsp/common.jsp" %>
<%@ page  language="java" import="java.util.*" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<head>
<link href="../../css/mainbody_style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../js/jquery-1.4.4.js" ></script>
<style type="text/css">
tr>td:nth-child(2n-1){text-align:right;}
</style>
</head>
<body>
<div style="width:90%;">
	<form method="post" id="formGrade" >
		<input type="hidden" name="position" value='<c:out value="${position}"/>' />
		<table style="width:100%;table-layout:fixed;line-height:4em;">
			<tr>
				<td>年级：</td>
				<td>
					<select name="gradeCode" id="gradeCode">
						<c:forEach items="${gradeList }" var="grade">
							<option value="<c:out value='${grade.dicCode}'/>"> <c:out value="${grade.dicValue }"/> 
						</c:forEach>
					</select>
				</td>
				<td>班级：</td>
				<td>
					<select name="classCode" id="classCode">
						<c:forEach var="i" begin="1" end="20">
							<option value="<c:out value='${i}'/>"> <c:out value="${i}"/>班
						</c:forEach>
					</select>
					
				</td>
				<td>专业类别：</td>
				<td>
					<select name="majorCode" id="majorCode">
						<c:forEach items="${majorList }" var="major">
							<option value="<c:out value='${major.dicCode}'/>"> <c:out value="${major.dicValue }"/> 
						</c:forEach>
					</select>
				</td>
			</tr>
			<tr>
				<td>班主任姓名：</td>
				<td>
					<input type="text" name="teacherName" id="teacherName" />
				</td>
				<td>性别：</td>
				<td>
					<input type="radio" name="gender" value="F"/>女
					<input type="radio" name="gender" value="M" checked="checked"/>男
				</td>
				<td>联系电话：</td>
				<td>
					<input type="text" name="telNo" id="telNo" />
				</td>
			</tr>
			<tr>
				<td colspan="6" style="text-align:center;">
					<input type="button" class="button_sub01" value="提交保存" onclick="saveData()"/>
				</td>
			</tr>
		</table>
	</form>
</div>

<script>
	function saveData(){
		var gradeCode = $("#gradeCode").val();
		var classCode = $("#classCode").val();
		var majorCode = $("#majorCode").val();
		var teacherName = $("#teacherName").val();
		var telNo = $("#telNo").val();
		if(gradeCode && classCode && majorCode && teacherName && telNo ){
			//校验号码是否为11位的电话
			if(!(/^1\d{10}$/.test(telNo))){
				alert("请输入正确的手机号码");
				return;
			}
			//校验号码是否为11位的电话
			if(!(/^[\u4e00-\u9fa5 ]{2,10}$/.test(teacherName))){
				alert("请输入老师的中文名字");
				return;
			}
//			$("#formGrade").attr("action","saveNewGradeInfo.do");
//			$("#formGrade").submit();
			$.ajax({
				url:"saveNewGradeInfo.do",
				type:"post",
				dataType:"text",
				data:$("#formGrade").serialize(),
				success:function(data){
					var resCode = data;
					if(resCode=="01"){
						alert("数据保存成功");
					}else if(resCode=="02"){
						alert("班级已经存在");
					}else if(resCode=="03"){
						alert("数据保存失败");
					}
				},
				error:function(){
					alter("保存失败");
				}
			});
		}else{
			alert("请将信息填充完整");
			return;
		}
	}
</script>
</body>